import java.sql.ClientInfoStatus;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>(10);
        list.add("你好");
        list.add("小霖");
        list.add("学习");
        list.add("数据结构");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) +" ");
        }
        System.out.println();
        System.out.println("=================");
        for (String x:list) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("=================");
        Iterator<String> iterator = list.iterator();//获取列表的迭代器
        while (iterator.hasNext()){//判断是否还有下一个元素可以访问
            System.out.print(iterator.next()+" ");//获取下一个元素并打印
        }
    }
    public static void main4(String[] args) {
        ArrayList<String> list = new ArrayList<>(10);
        System.out.println("====尾插元素====");
        list.add("hello");
        list.add("hello");
        list.add("你好");
        list.add("学习");
        list.add("数据结构");
        System.out.println(list);
        System.out.println("====在指定下标插入元素====");
        list.add(3,"小霖");
        list.add(4,"想要");
        System.out.println(list);
        System.out.println("====插入一个集合====");
        ArrayList<String> list1 = new ArrayList<>();
        list1.add("和");
        list1.add("唱歌");
        list.addAll(list1);
        System.out.println(list);
        System.out.println("====删除指定位置的元素====");
        System.out.println(list.remove(2));
        System.out.println(list);
        System.out.println("====删除出现的第一个想要删除的元素====");
        list.remove("hello");
        System.out.println(list);
        System.out.println("====获取指定下标的元素====");
        System.out.println(list.get(1));
        System.out.println("====将指定的下标上的元素替换成想要替换的元素====");
        System.out.println(list.set(3,"认真学习"));
        System.out.println(list);
        System.out.println("====判断是否包含指定的元素====");
        System.out.println(list.contains("小霖"));
        System.out.println(list.contains("nihao"));
        System.out.println("====查找第一次出现的元素====");
        list.add(5,"小霖");
        System.out.println(list);
        System.out.println(list.indexOf("小霖"));
        System.out.println("====查找最后一次出现的元素====");
        System.out.println(list.lastIndexOf("小霖"));
        System.out.println("====截取指定区间的元素====");
        System.out.println(list.subList(1, 5));
        System.out.println("====清空列表====");
        list.clear();
        System.out.println(list);
    }
    public static void main3(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        //指定初始容量构造
        ArrayList<Integer> list1 = new ArrayList<>(10);
        ArrayList<Integer> list2 = new ArrayList<>(list1);

    }
    public static void main2(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        System.out.println(myArrayList.indexOf(1));
        /*myArrayList.set(1,8);
        myArrayList.display();// 列表为空！*/
    }
    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        /*//向上转型
        IMyArrayList iMyArrayList = new MyArrayList();*/
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        System.out.println(myArrayList.size());
        myArrayList.display();
        System.out.println();
        System.out.println("===============");
        myArrayList.add(1,200);
        myArrayList.display();
        System.out.println();
        System.out.println("===============");
        System.out.println(myArrayList.indexOf(5));
        System.out.println(myArrayList.indexOf(7));
        System.out.println(myArrayList.contains(200));
        System.out.println(myArrayList.get(1));
        /*System.out.println(myArrayList.get(7));//error*/
        myArrayList.set(1,7);
        myArrayList.display();
        System.out.println();
        System.out.println("===============");
        myArrayList.remove(4);
        myArrayList.display();
        System.out.println();
        System.out.println("===============");
        myArrayList.clear();
        myArrayList.display();
    }
}
